//
//  LabelAndCollectionViewReusableView.m
//  14-CollectionViewTestAnswer
//
//  Created by 李昊林 on 16/8/2.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "LabelAndCollectionViewReusableView.h"
#define kCollectionViewReuse @"reuseSmall"
@interface LabelAndCollectionViewReusableView ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong)UICollectionView *collectionView;
@property (nonatomic, strong)UILabel *label;
@end
@implementation LabelAndCollectionViewReusableView
- (instancetype) initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if ( self) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 50)];
        _label.text = @"分类";
        [self addSubview:_label];
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
        flow.minimumLineSpacing = 5;
        flow.minimumInteritemSpacing = 5;
        flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        flow.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
//        _collectionView = [UICollectionReusableView alloc] initWithFrame:CGRectMake(0, 50, CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>), <#CGFloat height#>)
//        CGFloat height = CGRectGetHeight(frame) - 50 - 40;
//        flow.itemSize = CGSizeMake((CGRectGetWidth(frame) - 30) / 2, height / 3);
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, frame.size.width, frame.size.height - 50) collectionViewLayout:flow];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewReuse];
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 20;
}

- ( __kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewReuse forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    return cell;
}

@end
